import { http , md5} from 'snail-utils'
let  GetQueryString = function(name) {
  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  var r = window.location.href.substr(1).match(reg);
  if(r!=null)return unescape(r[2]); return null;
};
let options = {};
options.singConfig = "sunnyfix_sign";
options.beforeData = {};
options.beforeData.sunnyfix_timestamp = new Date().getTime();
options.beforeData.token = GetQueryString("token");
options.resolveSuccess = res => {
  if(res.data.code == 0){
    return true
  }else{
    if (res.data.message) {
      $toast.show(res.data.message, 3000)
    } else{
      $toast.show(`服务器出错，状态码<span class='text text-xl'>${res.data.code}</span>`, 3000)
    }
  }
};
options.resolveError = res => {
  throw new Error(res);
};

export { http , options }